package com.ruoyi.personnel.changes.event.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.personnel.changes.event.domain.EventRecord;
import com.ruoyi.personnel.changes.event.service.IEventRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 员工事件记录
 *
 * @author Drj 2021/6/28
 */
@RestController
@RequestMapping("/personnel/event")
@Api(value = "员工事件记录模块", tags = "员工事件记录接口")
public class EventRecordController extends BaseController {
    @Autowired
    private IEventRecordService eventRecordService;

    /**
     * 获取员工事件记录列表
     *
     * @param eventRecord
     * @return
     */
    @ApiOperationSupport(includeParameters = {"EventRecord.staffId", "EventRecord.eventRecordId", "EventRecord.eventRecordDate"})
    @ApiOperation(value = "获取员工事件记录列表",notes = "查询所有员工事件记录信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody EventRecord eventRecord) {
        startPage();
        List<EventRecord> eventRecordList = eventRecordService.selectEventRecordList(eventRecord);
        return getDataTable(eventRecordList);
    }

    /**
     * 导出员工事件记录
     *
     * @param eventRecord
     * @return
     */
    @PostMapping("/export")
    public AjaxResult export(@RequestBody EventRecord eventRecord) {
        List<EventRecord> list = eventRecordService.selectEventRecordList(eventRecord);
        ExcelUtil<EventRecord> util = new ExcelUtil<EventRecord>(EventRecord.class);
        return util.exportExcel(list, "员工事件记录数据");
    }

    /**
     * 新增员工事件记录
     *
     * @param eventRecord
     * @return
     */
    @ApiOperation(value = "新增员工事件记录", notes = "新增员工事件记录")
    @ApiImplicitParam(name = "eventRecord", value = "新增员工事件记录", dataType = "EventRecord")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody EventRecord eventRecord) {
        return toAjax(eventRecordService.insertEventRecord(eventRecord));
    }

    /**
     * 修改员工事件记录
     *
     * @param eventRecord
     * @return
     */
    @ApiOperation(value = "修改员工事件记录", notes = "修改员工事件记录")
    @ApiImplicitParam(name = "eventRecord", value = "修改员工事件记录", dataType = "EventRecord")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody EventRecord eventRecord) {
        return toAjax(eventRecordService.updateEventRecord(eventRecord));
    }

    /**
     * 删除员工事件记录
     * 仅修改删除标志位
     *
     * @param eventRecord
     * @return
     */
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody EventRecord eventRecord) {
        return toAjax(eventRecordService.updateEventRecordDeleteFlag(eventRecord));
    }

}
